package com.ljw.spring.annotation.bean;

import lombok.Data;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

/**
 * @FileName Bike
 * @Description TODO
 * @Author ljw
 * @Date 2021/2/1 23:53
 * @Version 1.0
 */
@Data
public class Bike implements InitializingBean,DisposableBean {
    private String name;
    public Bike() {
    }

    public Bike(String name) {
        this.name = name;
        System.out.println("有参构造 创建bike实例");
    }


    /**
     * bean销毁：让bean实现DisposableBean接口，重写destroy()方法，定义IOC容器关闭时，bean的销毁逻辑
     * @throws Exception
     */
    @Override
    public void destroy() throws Exception {
        System.out.println("bike实例销毁");
    }

    /**
     * bean初始化：让bean实现InitializingBean接口，重写afterPropertiesSet()方法，定义bean创建成功后bean的初始化逻辑
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("bike实例开始初始化");
    }
}
